import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:smart_translator/app/modules/videoCall/controller/utils.dart';
import 'package:smart_translator/app/style/widget_style.dart';
import 'package:get/get.dart';
import 'package:smart_translator/app/widgets/CommonWidgets.dart';
import 'package:tencent_rtc_sdk/trtc_cloud_video_view.dart';
import 'package:tencent_trtc_cloud/trtc_cloud_def.dart';

import '../controller/video_calling_controller.dart';
import 'CallParams.dart';

class VideoCallFooter extends StatefulWidget {
  VideoCallFooter({
    Key? key,
    required this.onHandUp,
    // required this.onSwitchCamera,
    required this.onMuteSpeaker,
    required this.onMuteMic,
    required this.onMuteVideo,
    required this.isOpenSpeaker,
    required this.isOpenMic,
    required this.isOpenCamera,
    required this.textSize,
    required this.callType,
    required this.changeSize,
  }) : super(key: key);
  final Function() onHandUp;
  // final Function() onSwitchCamera;
  final Function() onMuteSpeaker;
  final Function() onMuteMic;
  final Function() onMuteVideo;
  final isOpenSpeaker;
  final isOpenMic;
  final isOpenCamera;
  final textSize;
  final callType;
  final changeSize;

  @override
  _VideoCallFooter createState() => _VideoCallFooter();
}

class _VideoCallFooter extends State<VideoCallFooter> {

  late bool isOpenSpeakerState;
  late bool isOpenMicState;
  late bool isOpenCameraState;
  String fontSizeState = '';

  @override
  void initState() {
    super.initState();
    setState(() {
      isOpenSpeakerState = widget.isOpenSpeaker;
      isOpenMicState = widget.isOpenMic;
      isOpenCameraState = widget.isOpenCamera;
      fontSizeState = widget.textSize.toString();
    });
  }

  void changeFontSize(nSize) {
    setState(() {
      fontSizeState = nSize.toString();
    });
    widget.changeSize(nSize);
  }

  @override
  Widget build(BuildContext context) {
    return  Row(
      // mainAxisAlignment:  MainAxisAlignment.spaceBetween,
      children: [
        Flexible(
          flex: 1,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              InkWell(
                onTap: () {
                  setState(() {
                    isOpenSpeakerState = !isOpenSpeakerState;
                  });
                  widget.onMuteSpeaker();
                },
                child: Container(
                  padding: EdgeInsets.only(top: 6.h, bottom: 8.h),
                  child: Column(
                    children: [
                      Visibility(
                        visible: isOpenSpeakerState,
                        child: Image.asset(
                          'assets/images/video_sound.png',
                          width: 24.w,
                          height: 24.h,
                        ),
                      ),
                      Visibility(
                        visible: !isOpenSpeakerState,
                        child: Image.asset(
                          'assets/images/video_sound_disable.png',
                          width: 24.w,
                          height: 24.h,
                        ),
                      ),
                      Text('声音'),
                    ],
                  ),
                ),
              ),
              InkWell(
                onTap: () {
                  setState(() {
                    isOpenMicState = !isOpenMicState;
                  });
                  widget.onMuteMic();
                },
                child: Container(
                  padding: EdgeInsets.only(top: 6.h, bottom: 8.h),
                  child: Column(
                    children: [
                      Visibility(
                        visible: isOpenMicState,
                        child: Image.asset(
                          'assets/images/video_micro.png',
                          width: 24.w,
                          height: 24.h,
                        ),
                      ),
                      Visibility(
                        visible: !isOpenMicState,
                        child: Image.asset(
                          'assets/images/video_micro_disable.png',
                          width: 24.w,
                          height: 24.h,
                        ),
                      ),
                      Text('麦克风'),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
        Container(
          child: InkWell(
            onTap: () {
              videoUtil.showHandupDialog(context, widget.onHandUp);
            },
            child: Container(
              padding: EdgeInsets.only(top: 6.h, bottom: 8.h),
              child: Column(
                children: [
                  Image.asset(
                    'assets/images/video_call.png',
                    width: 48.w,
                    height: 48.h,
                  ),
                ],
              ),
            ),
          ),
        ),
        Flexible(
          flex: 1,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: [
              if(widget.callType =='video')
                InkWell(
                  onTap: () {
                    setState(() {
                      isOpenCameraState = !isOpenCameraState;
                    });
                    // this.onSwitchCamera();
                    widget.onMuteVideo();
                  },
                  child: Container(
                    padding: EdgeInsets.only(top: 6.h, bottom: 8.h),
                    child: Column(
                      children: [
                        Visibility(
                          visible: isOpenCameraState,
                          child: Image.asset(
                            'assets/images/video_camera.png',
                            width: 24.w,
                            height: 24.h,
                          ),
                        ),
                        Visibility(
                          visible: !isOpenCameraState,
                          child: Image.asset(
                            'assets/images/video_camera_disable.png',
                            width: 24.w,
                            height: 24.h,
                          ),
                        ),
                        Text('摄像头'),
                      ],
                    ),
                  ),
                ),
              InkWell(
                onTap: () {
                  videoUtil.showFontsizeDialog(
                    context,
                    fontSizeState,
                    changeFontSize,
                  );
                },
                child: Container(
                  child: Column(
                    children: [Text(fontSizeState), Text('字体大小')],
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }
}
